package com.telecom.cms.actions;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.telecom.cms.dao.SEG_BIZ_ATOM_DEFDAO;
import com.telecom.cms.dbconnect.Chinese;
import com.telecom.cms.dao.GetConnect;


import com.telecom.cms.dto.*;

/**
 * @author yueyingnishang
 * 
 */
public class OutputAction extends Action {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("JISAutoDetect");
		String templateId=request.getParameter("templateId");
		request.getSession().setAttribute("selectedtemplate", templateId);
		Connection con = GetConnect.getCsConnection();

		SEG_BIZ_ATOM_DEFDAO dao = new SEG_BIZ_ATOM_DEFDAO(con);
		String[] groupname = request.getParameterValues("type");
		List list = new ArrayList();

		for (int i = 0; i < groupname.length; i++) {

			String[] atomvalue = request.getParameterValues(groupname[i]);

			for (int j = 0; j < atomvalue.length; j++) {
				SEG_BIZ_ATOM_DEFDTO dto = new SEG_BIZ_ATOM_DEFDTO();

				int atomid = Integer.parseInt(atomvalue[j]);
				dto = dao.findById(atomid);
				list.add(dto);
			}

		}

		// Enumeration paramNames = request.getParameterNames();
		// Connection con = GetConnect.getConnection();
		// SEG_BIZ_ATOM_DEF_NEWDAO dao = new SEG_BIZ_ATOM_DEF_NEWDAO(con);
		// List list = new ArrayList();
		// while (paramNames.hasMoreElements()) {
		//
		// SEG_BIZ_ATOM_DEF_NEWDTO dto = new SEG_BIZ_ATOM_DEF_NEWDTO();
		// String paramName = (String) paramNames.nextElement();
		// if (!paramName.equals("Submit")&&!paramName.equals("type")) {
		//
		// String value = request.getParameter(paramName);
		//
		// int atomid = Integer.parseInt(value);
		//
		// dto = dao.findById(atomid);
		//
		// list.add(dto);
		//
		// }
		//
		// }
		// List outputlist = new ArrayList();
		//
		// for (int i = 0; i < list.size(); i++) {
		//
		// SEG_BIZ_ATOM_DEF_NEWDTO dto = (SEG_BIZ_ATOM_DEF_NEWDTO) list.get(i);
		//
		// OutputDTO outputdto = new OutputDTO(dto.getBAS_TABLE_NAME(), dto
		// .getBIZ_ATOM_NAME(), dto.getBAS_TABLE_COL_NAME(), dto
		// .getBIZ_ATOM_ID(), dto.getCDE_SRC_TABLE_NAME(), dto
		// .getSHOW_TYPE_ID());
		//
		// outputlist.add(dto);
		// }

		request.getSession().setAttribute("Outputlist", list);

		return mapping.findForward("success");
	}

}
